/*
 * DBHelper.h
 *
 *  Created on: Jan 23, 2012
 *      Author: hduser
 */

#ifndef DBHELPER_H_
#define DBHELPER_H_

#include "mysql_connection.h"
#include "mysql_driver.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace sql;

namespace database {

class DBHelper {
public:
	DBHelper();
	virtual ~DBHelper();
	int logErrorToDB(char* host, char* clientip, char* serverip, char* location, char* errormsg, char* note);
	int logErrorToDB_1(char* host, char* clientip, char* serverip, char* location, char* errormsg, char* note);
	sql::ResultSet* checkRequest(int VendorID, char* file);
	sql::ResultSet* getEdgeServerGroup();
	sql::ResultSet* getEdgeServersInGroup(int EdgeServerGroupID);
	sql::ResultSet* createRequest(int VendorID, char* file, char* dateUpdated, size_t fileSize, int chunkCount, int EdgeServerGroupID);
	sql::ResultSet* createRequestItem(int RequestID, int chunkIndex, size_t chunkSize, int EdgeServerID);
	int makeRequestInactive(int RequestID);
	int updateRequestStatus(int RequestID, int RequestStatusID);
	int updateRequestItemStatus(int RequestItemID, int RequestItemStatusID);
	int ExecuteNonQuery(char* command, char* argtypes, ...);
	sql::ResultSet* ExecuteQuery(char* command, char* argtypes, ...);
	sql::ResultSet* getActiveRequestItems(int VendorID, char* file);
	void disconnectDB();


	sql::Connection* con;

};

}

#endif /* DBHELPER_H_ */
